import React from 'react';
import type {Router as RemixRouter} from "@remix-run/router/dist/router";
import RouteResolve from "./RouteResolve";
import {createBrowserRouter, RouteObject} from "react-router-dom";
import {MessageInstance} from "antd/es/message/interface";
import IndexPage from "./IndexPage";
import GlobalHandler from "../global/GlobalHandler";

const useRouteAutoConfig = (message: MessageInstance):RemixRouter => {
    let resolve: any = new RouteResolve(message);
    let tempRoute = resolve.parseRoute() ;
    const globalHandler = GlobalHandler.getInstance() ;
    globalHandler.setMessage(message) ;
    const routeObjects: RouteObject[] = [
        {
            path: "/",
            element: <IndexPage/> ,
            children: tempRoute
        }
    ] ;
    let route = createBrowserRouter(routeObjects);
    resolve = null ;
    tempRoute = [] ;

    return route;
};

export default useRouteAutoConfig;